package com.itheima.dubbo.web;

import com.itheima.dubbo.User;
import com.itheima.dubbo.UserFace;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class UserController {

    @DubboReference
    private UserFace userFace;

    @GetMapping("hello")
    public String hello(String userName) {
        String result = userFace.hello(userName);
        return result;
    }

    @GetMapping("findOne")
    public User findOne(Long id) {
        RpcContext context = RpcContext.getContext();
        context.setAttachment("it","上海黑马");
        User user = userFace.findById(new User(id,"上海"));
        return user;
    }
}
